package cn.tianyigps.tianyigpsm7clean.dao;

import cn.tianyigps.tianyigpspublic.bean.EquipmentModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IDEA
 *
 * @description: M7 设备清洗
 * @author: cui.guibin
 * @create: 2019/4/18 13:27
 **/
@Repository
public class EquipmentDaoImpl implements EquipmentDao {

    @Autowired
    private MongoTemplate mongoTemplate;

    public EquipmentModel findByEquipmentId(String equipmentId){

        Criteria criteria = Criteria.where("equipmentId").is(equipmentId);
        Query query = new Query(criteria);
        return mongoTemplate.findOne(query, EquipmentModel.class , "latestEquipmentData");

    }

    @Override
    public void insertBatch(List<EquipmentModel> equipmentModels,String collectionName) {
        mongoTemplate.insert(equipmentModels,collectionName);
    }

    @Override
    public void save(EquipmentModel equipmentModel) {
        mongoTemplate.save(equipmentModel,"m7LatestEquipmentData");
    }


}
